//
//  CNMarketViewController.m
//  BeeQuick_19
//
//  Created by 张旭峰 on 16/9/23.
//  Copyright © 2016年 CN Team. All rights reserved.
//

#import "CNMarketViewController.h"
#import "CNkindModel.h"
#import "CNdetailsModel.h"
#import "CNdetailsCell.h"
#import "SVProgressHUD.h"
#import "CNHTTPSessionManager.h"
#import "CNArchiverTools.h"
#import "CNProductViewController.h"
#import "Scan_VC.h"
#import "CNRefreshHeaderView.h"
static NSString *kindID = @"kindID";
static NSString *detailsID = @"detailsID";


@interface CNMarketViewController ()<UITableViewDelegate,UITableViewDataSource,detailsCellDelegate>

@property(nonatomic,strong)CNdetailsModel * model;
//@property(nonatomic,weak)UITableView *StableView;

@property(nonatomic, weak)UIButton* cityBtn;

@end

@implementation CNMarketViewController
{
    //种类view
    UITableView *_kindView;
    //详情View
    UITableView *_detailsView;
    //种类列表
    NSArray <CNkindModel *>*_kindList;
    //详情列表
    NSArray<CNdetailsModel *>*_detailsList;
    NSArray<CNdetailsModel *>*_detailsList1;

    //选中种类的ID
    NSString *_kindID;
    //详情列表组头
    NSString *_name;
    //选中模型数据
    NSMutableArray<CNdetailsModel *> *_detailsArrM;
    //选中模型字典
    NSMutableDictionary *_detailsDict;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    

    //添加搜索栏右侧button
    
   // UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"跳转" style:UIBarButtonItemStylePlain target:self action:@selector(pushVC)];
    
    //设置颜色
   // item.tintColor = [UIColor blueColor];
    
   // self.navigationItem.rightBarButtonItem = item;
    
    //self.view.backgroundColor = [UIColor clearColor];
   // self.tabBarItem.selectedImage = [[UIImage imageNamed:@"v2_order_r"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:252/255.0 green:210/255.0 blue:48/255.0 alpha:1.0]];
   // [self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
    

    _kindID = @"a106";
    [self loadData];
    [self setupUI];
    [self setupRefresh];
    //实例化数组
    _detailsArrM = [[NSMutableArray alloc] init];
    _detailsDict = [[NSMutableDictionary alloc] init];
}

- (void)pushVC{
   
    //设置底部Bar隐藏
    self.tabBarController.tabBar.hidden = YES;
    //跳转时隐藏
    self.hidesBottomBarWhenPushed = YES;
    //[self.navigationController pushViewController:controller animated:YES];
    
    [self.navigationController pushViewController:[NSClassFromString(@"CNNavMarketViewController") new] animated:true];
    //返回时关闭隐藏
    self.hidesBottomBarWhenPushed = NO;
}
-(void)loadData
{
    
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    //判断是否展示新特性界面
    if (![defaults stringForKey:@"isOne"]) {
  
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    // type = 0/1
    [param setValue:@"5" forKey:@"call"];

    CNHTTPSessionManager * NETManager = [CNHTTPSessionManager  sharedManager];
    [NETManager request:@"POST" componentUrlString:@"supermarket.json.php" parameters:param completion:^(id response, NSError *error) {
        
        //把数据保存到沙盒中
        [CNArchiverTools archiverObject:response ByKey:@"dataCache" WithPath:@"data.plist"];
        
        //取出菜单对应数组
        NSArray<NSDictionary *> *kindArr = response[@"data"][@"categories"];
        
        //字典转模型
        _kindList = [NSArray yy_modelArrayWithClass:[CNkindModel class] json:kindArr];
        
        //取出详情对应字典
        NSDictionary *dictDetail = response[@"data"][@"products"];
        //根据key取出数组
        NSArray *detailsArr = [dictDetail objectForKeyedSubscript:_kindID];
        //字典转模型
        _detailsList = [NSArray yy_modelArrayWithClass:[CNdetailsModel class] json:detailsArr];
        
        
        
        //刷新界面
        
        
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            [_kindView reloadData];
            
            [_detailsView reloadData];
            
        }];

        
    }];
    }
    //把用户是否是首次使用App的信息存入沙盒
    [defaults setObject:@"非首次使用应用" forKey:@"isOne"];
    
     NSString *homeDir = NSHomeDirectory();
    
    NSDictionary *dict = [CNArchiverTools unarchiverObjectByKey:@"dataCache" WithPath:@"data.plist"];
    
    
    //取出菜单对应数组
    NSArray<NSDictionary *> *kindArr = dict[@"data"][@"categories"];
    
    //字典转模型
    _kindList = [NSArray yy_modelArrayWithClass:[CNkindModel class] json:kindArr];
    
    
    //取出详情对应字典
    NSDictionary *detailsDict = dict[@"data"][@"products"];
   
    
    //根据key取出数组
    NSArray *detailsArr = [detailsDict objectForKeyedSubscript:_kindID];
    //字典转模型
    _detailsList = [NSArray yy_modelArrayWithClass:[CNdetailsModel class] json:detailsArr];
    _detailsList = [[SQLiteManager sharedSQLiteManager] getValueWith:_detailsList];
    
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        
        [_kindView reloadData];
        
        [_detailsView reloadData];
        
    }];
    

    
    
}
-(void)setupUI
{
    
    
    
    
    UITableView *kindView = [[UITableView alloc] init];
    
    kindView.tableFooterView = [[UIView alloc] init];
    //赋值
    _kindView = kindView;
    //cell行高
    kindView.rowHeight = 40;
    [self.view addSubview:kindView];
    
    //约束
    [kindView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.bottom.equalTo(self.view);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(88);
    }];
    UIView * View2 = [[UIView alloc]init];
    [self.view addSubview: View2];
   // View2.backgroundColor = [UIColor redColor];
    [View2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(64);
        make.left.equalTo(kindView.mas_right);
        make.right.equalTo( self.view.mas_right);
        make.bottom.mas_equalTo(-563);
        
        
    }];
    UIButton *button1 = [[UIButton alloc]init];
    UIButton *button2 = [[UIButton alloc]init];
    UIButton *button3 = [[UIButton alloc]init];
   
    [View2 addSubview:button1];
  
    [button1 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor orangeColor]forState:UIControlStateHighlighted];
    button1.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [button1 setTitle:@"综合排序" forState:UIControlStateNormal];
    
    
    
    [View2 addSubview:button2];
    
    [button2 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor orangeColor]forState:UIControlStateHighlighted];
    button2.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [button2 setTitle:@"按价格" forState:UIControlStateNormal];
    [View2 addSubview:button3];
    
    [button3 setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor orangeColor]forState:UIControlStateHighlighted];
    button3.titleLabel.font = [UIFont systemFontOfSize: 14.0];
    [button3 setTitle:@"按销量" forState:UIControlStateNormal];
    
     [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.left.bottom.equalTo(View2);
        // make.height.equalTo(View2);
         make.width.equalTo(button2);
         
     }];
    
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(View2);
        make.left.equalTo(button1.mas_right);
        // make.height.equalTo(View2);
        make.width.equalTo(button3);
        
    }];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(View2);
        make.left.equalTo(button2.mas_right);
        make.width.equalTo(button1);
       // make.height.equalTo(View2);
        make.right.equalTo(View2);
        
    }];
    button1.tag = 1;
    button2.tag = 2;
    button3.tag = 3;
    [button1 addTarget:self action:@selector(ButtonClick:)forControlEvents:UIControlEventTouchUpInside];
    [button2 addTarget:self action:@selector(ButtonClick:)forControlEvents:UIControlEventTouchUpInside];
    [button3 addTarget:self action:@selector(ButtonClick:)forControlEvents:UIControlEventTouchUpInside];
    UITableView *detailsView = [[UITableView alloc] init];
    
    detailsView.rowHeight = 100;
    detailsView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
    _detailsView = detailsView;
    [self.view addSubview:detailsView];
    
    //约束
    [detailsView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(View2.mas_bottom);
        make.right.bottom.equalTo(self.view);
        make.left.equalTo(kindView.mas_right);
        
    }];
    
    
  //  UIView * View1 = [[UIView alloc]init];
   // View1.bounds=CGRectMake(0, 0, 88, 40);
//    View1.backgroundColor=[UIColor redColor];
    //_kindView.tableHeaderView=View1;
   
   
    
    //View2.backgroundColor = [UIColor redColor];
    //detailsView.tableHeaderView = View2;
    
    
    //设置代理
    kindView.dataSource = self;
    kindView.delegate = self;
    
    detailsView.delegate = self;
    detailsView.dataSource = self;
    
    //注册
    [kindView registerClass:[UITableViewCell class] forCellReuseIdentifier:kindID];
    [detailsView registerNib:[UINib nibWithNibName:@"CNdetailsCell" bundle:nil] forCellReuseIdentifier:detailsID];
    //self.navigationController.navigationBar.backgroundColor = [UIColor lightGrayColor];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    // [self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
    UIImageView *view = [[UIImageView alloc] initWithFrame:detailsView.bounds];
    
    view.image = [UIImage imageNamed:@"v2_placeholder_half_size"];
    view.contentMode = UIViewContentModeScaleToFill;
    [view sizeToFit];
    detailsView.tableFooterView = view;
    UIBarButtonItem* searchBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_search"] style:UIBarButtonItemStylePlain target:self action:@selector(pushVC)];
    self.navigationItem.rightBarButtonItem = searchBtn;
    
    //添加左侧的扫一扫UIBarButtonItem
    UIBarButtonItem* sweepBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_black_scancode"] style:UIBarButtonItemStylePlain target:self action:@selector(jumpTpSweep)];
    self.navigationItem.leftBarButtonItem = sweepBtn;
    
    UITextField* tf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:tf];
    
    
    UIButton* cityBtn = [[UIButton alloc] init];
    [cityBtn setTitle:@"配送至:您的位置" forState:UIControlStateNormal];
    
    [cityBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    cityBtn.titleLabel.font = [UIFont systemFontOfSize:14.0f];
//    [cityBtn addTarget:self action:@selector(jumpToLocation) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = cityBtn;
    self.cityBtn = cityBtn;
    
   }


/*
 
 
 CNRefreshHeaderView *header = [CNRefreshHeaderView headerWithRefreshingBlock:^{
 
 self.title = @"";
 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] init];
 
 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
 
 self.title = @"首页";
 [self loadNavigationItems];
 
 [self.tableView.mj_header endRefreshing];
 
 [self loadAlertView];
 });
 }];
 self.tableView.mj_header = header;
 
 */

-(void)ButtonClick:(UIButton*)button
{
  NSMutableArray* array = _detailsList1;
    
    _detailsList1 = [self sortArray:array tag:button.tag];
    _detailsList = _detailsList1;
    [_detailsView reloadData];
    
}
#pragma mark - 排序
//排序方法
- (NSMutableArray *)sortArray:(NSMutableArray *)array tag:(int )tag{
    
    switch ( tag ) {
            //综合排序
        case 1:
            
            [array sortUsingComparator:^NSComparisonResult(CNdetailsModel *  _Nonnull obj1, CNdetailsModel *  _Nonnull obj2) {
                
                if (obj1.sort.integerValue < obj2.sort.integerValue) {
                    return NSOrderedAscending;
                }
                return NSOrderedDescending;
            }];
            break;
        case 2:
            [array sortUsingComparator:^NSComparisonResult(CNdetailsModel *  _Nonnull obj1, CNdetailsModel *  _Nonnull obj2) {
                
                if (obj1.price< obj2.price) {
                    return NSOrderedAscending;
                }
                return NSOrderedDescending;
            }];
            
            break;
        case 3:
            [array sortUsingComparator:^NSComparisonResult(CNdetailsModel *  _Nonnull obj1, CNdetailsModel *  _Nonnull obj2) {
                
                if (obj1.count > obj2.count) {
                    return NSOrderedAscending;
                }
                return NSOrderedDescending;
            }];
            
            break;
        default:
            break;
    }
    return array;
}
-(void)setupRefresh
{
    _detailsView.mj_header=[CNRefreshHeaderView headerWithRefreshingBlock:^{
        [self loadNEWData];
    }];

}
-(void)loadNEWData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    // type = 0/1
    [param setValue:@"5" forKey:@"call"];
    
    CNHTTPSessionManager * NETManager = [CNHTTPSessionManager  sharedManager];
    [NETManager request:@"POST" componentUrlString:@"supermarket.json.php" parameters:param completion:^(id response, NSError *error) {
        
        //把数据保存到沙盒中
        [CNArchiverTools archiverObject:response ByKey:@"dataCache" WithPath:@"data.plist"];
        
        //取出菜单对应数组
        NSArray<NSDictionary *> *kindArr = response[@"data"][@"categories"];
        
        //字典转模型
        _kindList = [NSArray yy_modelArrayWithClass:[CNkindModel class] json:kindArr];
        
        //取出详情对应字典
        NSDictionary *dictDetail = response[@"data"][@"products"];
        //根据key取出数组
        NSArray *detailsArr = [dictDetail objectForKeyedSubscript:_kindID];
        //字典转模型
        _detailsList = [NSArray yy_modelArrayWithClass:[CNdetailsModel class] json:detailsArr];
        
        //刷新界面
        
        
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            
            [_kindView reloadData];
            
            [_detailsView reloadData];
            
        }];
        
        [_detailsView.mj_header endRefreshing];
        [self loadAlertView];
    }];

}

#pragma mark 提示框
- (void)loadAlertView{
    UILabel * tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    tipLabel.center = _detailsView.center;
    [tipLabel setText:@"没有数据更新"];
    tipLabel.backgroundColor = [UIColor blackColor];
    tipLabel.layer.cornerRadius = 5;
    tipLabel.layer.masksToBounds = YES;
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:tipLabel];
    [UIView animateWithDuration:2.0 animations:^{
        tipLabel.alpha = 0.0;
    } completion:^(BOOL finished) {
        [tipLabel removeFromSuperview];
    }];
}

-(void)setModel:(CNdetailsModel *)model
{
    _model = model;
    
}
/*-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (tableView == _detailsView) {
        
        if (_name.length == 0) {
            
            CNkindModel *model = _kindList[section];
            
            return model.name;
        }else{
            return _name;
        }
        
    }
    return nil;
}
*/
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _kindView) {
        
        NSDictionary *dict = [CNArchiverTools unarchiverObjectByKey:@"dataCache" WithPath:@"data.plist"];
        
        _kindID = _kindList[indexPath.row].id;
        
        //        NSLog(@"%zd",_kindList[indexPath.row].index);
        _name = _kindList[indexPath.row].name;
        //根据key取出数组
        NSArray *detailsArr = [dict[@"data"][@"products"] objectForKeyedSubscript:_kindID];
        
        //字典转模型
        _detailsList = [NSArray yy_modelArrayWithClass:[CNdetailsModel class] json:detailsArr];
        
        _detailsList1 = _detailsList;
        //从新刷新详情列表
        
        [_detailsView reloadData];
        NSIndexPath *first = [NSIndexPath indexPathForRow:0 inSection:0];
       // [_detailsView selectRowAtIndexPath:first animated:NO scrollPosition:UITableViewScrollPositionTop];
        [_detailsView scrollToRowAtIndexPath:first atScrollPosition:UITableViewScrollPositionTop animated:NO];
        
        return;
    }
    CNProductViewController *controller = [[CNProductViewController alloc]init];
    
    CNdetailsModel *model = _detailsList[indexPath.row];
    
    CNdetailsModel *modelM = [_detailsDict objectForKey:model];
    
    //    NSLog(@"跳进了---->%@",model);
    if (modelM.count != 0) {
        
        controller.model = modelM;
        controller.model.count = modelM.count;
        
    }else{
        
        controller.model = model;
        controller.model.count = model.count;
    }
    
    //设置底部Bar隐藏
    self.tabBarController.tabBar.hidden = YES;
    //跳转时隐藏
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
    //返回时关闭隐藏
    self.hidesBottomBarWhenPushed = NO;

    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _detailsView ) {
        
        return _detailsList.count;
        
    }
    return _kindList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //判断是否是详情列表
    if (tableView == _detailsView) {
        
        
        CNdetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:detailsID forIndexPath:indexPath];
        
        cell.delegate = self;
        CNdetailsModel *model = _detailsList[indexPath.row];
            cell.model = model;
            
        
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        cell.selectedBackgroundView = view;
        
        
        
        CNdetailsModel *oldModel = [_detailsDict objectForKey:model.name];
        if (oldModel.count != 0 ) {
            
            cell.model = oldModel;
            
            cell.countLabel.text = [NSString stringWithFormat:@"%zd",oldModel.count];
            
            cell.reduceButton.hidden = NO;
            cell.countLabel.hidden = NO;
            
            
            return cell;
        }
        
        cell.model = model;
        
        if (model.pm_desc.length != 0) {
            
            cell.pm_descImageView.hidden = NO;
        }else{
            
            cell.pm_descImageView.hidden = YES;
            
        }
        
        if (model.count < 1) {
            cell.reduceButton.hidden = YES;
            cell.countLabel.text = @(0).description;
            cell.countLabel.hidden = YES;
        }else{
            cell.reduceButton.hidden = NO;
            cell.countLabel.hidden = NO;
            cell.countLabel.text = @(model.count).description;
        }
        return cell;

        //    return cell;
    }
        
    
        

    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kindID forIndexPath:indexPath];
    
    
    //取出模型数据
    CNkindModel *model = _kindList[indexPath.row];
    
    //赋值
    cell.textLabel.text = model.name;
    
    //设置字体大小
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    cell.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
    
    //选中背景颜色
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    cell.selectedBackgroundView = view;
    
    return cell;

}
#pragma mark - detailsCellDelegate代理方法
//增加
-(void)addCountWithCell:(CNdetailsCell *)cell model:(CNdetailsModel *)model poin:(CGPoint)startPoin frame:(CGRect)frame
{
    [_detailsDict setObject:model forKey:model.name];
    _model = model;
    _model.count = model.count;
    // 将模型存入数组
    [[SQLiteManager sharedSQLiteManager]charu:_model With:1];
    
    if (![_detailsArrM containsObject:model]) {
        [_detailsArrM addObject:model];
    }
    UIImageView *imgView = [[UIImageView alloc]init];
    // sd缓存的图片提取
    UIImage *cachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:model.img];
    imgView.image = cachedImage;
    
    //    imgView.layer.cornerRadius = 75;
    //    imgView.backgroundColor = [UIColor clearColor];
    imgView.bounds = CGRectMake(0, 0, 80,80);
    imgView.frame = frame;
    imgView.center = startPoin;
    UIWindow *wind = [UIApplication sharedApplication].keyWindow;
    
    [wind addSubview:imgView];
    
    // 动画
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    [anim setValue:imgView forKey:@"img"];
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:startPoin];
    CGPoint endP = CGPointMake(wind.bounds.size.width * 0.625, wind.bounds.size.height - 30);
    CGPoint controlP = CGPointMake(startPoin.x + 70, startPoin.y + 10);
    [path addQuadCurveToPoint:endP controlPoint:controlP];
    anim.path = path.CGPath;
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    anim.duration = 0.8;
    anim.delegate = self;
    [imgView.layer addAnimation:anim forKey:nil];
    [UIView animateWithDuration:1 animations:^{
        
        imgView.transform = CGAffineTransformScale(imgView.transform, 0.4, 0.4);
        imgView.alpha = 0.4;
    }];


}
// 核心动画的代理方法
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    
    // 1.移除图片框
    // - 取出图片框
    UIImageView *imgV = [anim valueForKey:@"img"];
    // - 移除核心动画
    [imgV.layer removeAllAnimations];
    
    // - 移除
    [imgV removeFromSuperview];
    
    
}
//删除
-(void)descressCountWithCell:(CNdetailsCell *)cell model:(CNdetailsModel *)model
{
    
    [[SQLiteManager sharedSQLiteManager]charu:_model With:-1];
   /* if (model.count == 0) {
        
        [_detailsArrM removeObject:model];
    }*/
    
}
-(void)jumpTpSweep
{
    Scan_VC *VC = [[Scan_VC alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
    
}
/*
-(void)viewDidLayoutSubviews
{
    
    if ([_kindView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_kindView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    
    if ([_kindView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_kindView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
*/
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _detailsList = [[SQLiteManager sharedSQLiteManager] getValueWith:_detailsList];
     [_detailsView reloadData];
    self.navigationController.navigationBar.hidden=NO;
    
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    
   
    //[[NSNotificationCenter defaultCenter] postNotificationName:HMFoodListNotification object:self userInfo:userInfo];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
